﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using XinYi.CrookedShowMode;

namespace XinYi.CrookedShow.BLL
{
    public class OrderInformationService : BaseService<OrderInformation>
    {
        #region 分页
        public List<OrderInformation> GetOrderInformation(string adddate, string enddate, string biaohao)
        {
            using (var db = new CrookedShowEntities())
            {
                var result = from a in db.Order
                             join b in db.Order_Detail
                             on a.Order_Id equals b.Order_Id
                             select new OrderInformation()
                             {
                                 Order_Id = a.Order_Id,
                                 Order_No = a.Order_No,
                                 Product_Name = b.Product_Name,
                                 Order_Money = a.Order_Money,
                                 District_Money = a.District_Money,
                                 CreateTime = a.CreateTime,
                                 Product_Cnt = b.Product_Cnt,
                                 Order_Status = a.Order_Status
                             };
                DateTime time1 = Convert.ToDateTime(adddate);
                DateTime time2 = Convert.ToDateTime(enddate);
                if (!string.IsNullOrEmpty(adddate) && !string.IsNullOrEmpty(enddate)&&!string.IsNullOrEmpty(biaohao))
                {
                    return result.Where(a => a.CreateTime > time1 && a.CreateTime < time2 &&a.Order_No.ToString().Contains(biaohao)).ToList();
                }
                else if (!string.IsNullOrEmpty(adddate) && !string.IsNullOrEmpty(enddate))
                {
                    return result.Where(a => a.CreateTime > time1 && a.CreateTime < time2).ToList();
                }
                else if (!string.IsNullOrEmpty(adddate) && !string.IsNullOrEmpty(biaohao))
                {
                    return result.Where(a => a.CreateTime > time1 && a.Order_No.ToString().Contains(biaohao)).ToList();
                }
                else if (!string.IsNullOrEmpty(adddate))
                {
                    return result.Where(a => a.CreateTime > time1).ToList();
                }
                else if (!string.IsNullOrEmpty(enddate))
                {
                    return result.Where(a => a.CreateTime < time2).ToList();
                }
                else if (!string.IsNullOrEmpty(biaohao))
                {
                    return result.Where(a => a.Order_No.ToString().Contains(biaohao)).ToList();
                }
                else
                {
                    return result.ToList();
                }
            }
        }
        #endregion
    }
}
